package com.itheima.info.manage.dao;

import com.itheima.info.manage.domain.Student;

import java.util.ArrayList;

/**
 * @author Yao
 * @date 2020/6/20 0020
 **/
public class StudentDao {

    private static ArrayList<Student> list = new ArrayList<>();

    static {
        list.add(new Student("001", "张三", 18, "2002-01"));
        list.add(new Student("002", "李四", 23, "1999-01"));
    }

    public int getIndex(String sid) {
        int index=-1;
        for (int i = 0; i < list.size(); i++) {
            if (sid.equals(list.get(i).getSid())){
                index=i;
            }
        }

        return index;
    }

    public ArrayList<Student> queryStudents() {
        return list;
    }

    public void addStudent(Student student) {
        list.add(student);
    }

    public void deleteStudent(int index) {
        list.remove(index);
    }

    public void updateStudent(Student stu) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getSid().equals(stu.getSid())){
                list.set(i, stu);
            }
        }

    }
}
